package com.heima.admin.controller;

import com.heima.admin.annotation.OperationFill;
import com.heima.admin.service.IAdminChannelService;
import com.heima.api.admin.IAdminClient;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/v1/channel")
public class AdminChannelController {

    @Autowired
    private IAdminClient adminClient;
    @Autowired
    private IAdminChannelService adminChannelService;

    /**
     * 保存频道
     * @param wmChannel
     * @return
     */
    @OperationFill
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        log.info("添加频道：{}",wmChannel);
        return adminClient.addChannel(wmChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @OperationFill
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id){
        log.info("删除频道：{}",id);
        return adminChannelService.deleteChannel(id);
    }

    /**
     * 修改频道
     * @param wmChannel
     * @return
     */
    @OperationFill
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel){
        log.info("修改频道：{}",wmChannel);
        return adminChannelService.updateChannel(wmChannel);
    }

    /**
     * 频道名称模糊分页查询
     * @param channelDto
     * @return
     */
    @OperationFill
    @PostMapping("/list")
    public PageResponseResult channelList(@RequestBody ChannelDto channelDto){
        log.info("管理端分页查询：{}",channelDto);
        return adminClient.findChannelList(channelDto);
    }
}
